package adoption;

import java.util.HashMap;

import book.Book;

import exception.InvalidAdoptionException;
import exception.InvalidNameException;

/**
 * Represents a collection of adoptions
 * @author SJP
 *
 */
public class AdoptionMap extends HashMap<Integer,Adoption>{
	
	/**
	 * @return the adoption with the given id
	 * @throws InvalidNameException if there is no adoption with the given id
	 */
	public Adoption getAdoption(Integer id) throws InvalidNameException {
		if (super.containsKey(id))
			return super.get(id);
		else
			throw new InvalidNameException("AdoptionMap get: id \""+id+"\" not valid.");
	}
	
	/**
	 * Add an adoption with the given id
	 * @param id identifier of the given adoption
	 * @param a adoption to add
	 * @return the adoption if the add was successful
	 * @throws InvalidNameException if the adoption already exists.
	 */
	public Adoption addAdoption(Adoption a) throws InvalidAdoptionException{
		if (super.containsValue(a))
			throw new InvalidAdoptionException("AdoptionMap put: adoption \""+a.getID()+"\" already exists.");
		else
			return super.put(a.getID(), a);
	}
	
	public boolean contains(Book b) {
		return super.containsValue(b);
	}
	
}
